# -*- coding: utf-8 -*-
#Modulos standars de django
import datetime
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext

#Modulos personales
from mundofacu.usuarios.funciones import exist
from mundofacu.usuarios.models import carreras
from mundofacu.news.models import noticias
from funciones import voice


#Modulos de usuario
def Vindex(request):
	lcarreras = carreras.objects.all()
	for c in lcarreras:	c.voicename = voice(c.voicename)
	return render_to_response('voice/index.html', {'carreras': lcarreras}, context_instance=RequestContext(request))


def Vgeneral(request):
	lnoticias= noticias.objects.filter(fecha_publicacion__lte=datetime.date.today(), fecha_expiracion__gte=datetime.date.today())[::-1][:5]
	for n in lnoticias: n.titulo = voice(n.titulo)
	return render_to_response('voice/noticias.html', {'opcion':'all topics', 'noticias': lnoticias}, context_instance=RequestContext(request))


def Vcarrera(request, id):
	lnoticias= noticias.objects.filter(fecha_publicacion__lte=datetime.date.today(), fecha_expiracion__gte=datetime.date.today(), carrera=id)[::-1][:5]
	for n in lnoticias: n.titulo = voice(n.titulo)
	if exist(carreras,"id",id): return render_to_response('voice/noticias.html', {'opcion':voice(carreras.objects.get(id=id).nombre), 'noticias': lnoticias})
	else: return Vgeneral(request)


def Vernew(request,id):
	if exist(noticias,"id",id):
		n = noticias.objects.get(id=id)
		n.titulo= voice(n.titulo)
		n.resumen= voice(n.resumen)
		return render_to_response('voice/ver.html', {'noticia': n}, context_instance=RequestContext(request))
	else: return Vgeneral(request)


def Vstop(request):
	return render_to_response('voice/stop.html', {}, context_instance=RequestContext(request))